package com.charon.auth.demo.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.Callable;

/**
 * @ClassName: AsyncController
 * @Description: 多线程异步处理请求
 * @Author Charon [248135724@qq.com]
 * @Date 2019/1/19 20:56
 * @Version V 1.0
 */
@Slf4j
@RestController
@RequestMapping("/async")
public class AsyncController {

    /**
     * @Description 单线程模拟处理等待
     * @Author Charon [248135724@qq.com]
     * @Date 2019/1/20 19:14
     * @Param []
     * @return java.lang.String
     */
    @RequestMapping("/order")
    public String order() throws InterruptedException {
        log.info("主线程开始");
        Thread.sleep(3000);
        log.info("主线程结束");
        return "success";
    }

    @RequestMapping("/async")
    public Callable<String> doAsync(){
        log.info("主线程开始");
        Callable<String> result=new Callable<String>() {
            @Override
            public String call() throws Exception {
                log.info("副线程开始");
                Thread.sleep(3000);
                log.info("副线程结束");
                return "success";
            }
        };
        log.info("主线程结束");
        return result;
    }
}
